package cn.zy.company.servlet;

import cn.zy.company.entity.Member;
import cn.zy.company.entity.News;
import cn.zy.company.entity.PageObj;
import cn.zy.company.entity.Work;
import cn.zy.company.service.MemberService;
import cn.zy.company.service.NewsService;
import cn.zy.company.service.WorkService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {

            NewsService newsService = new NewsService();
            WorkService workService=new WorkService();
            PageObj<News> pageObj = new PageObj<News>();
            PageObj<News> all = newsService.findAll(pageObj);
            req.setAttribute("news", all);
            PageObj<Work> pageObj1 = new PageObj<Work>();
            PageObj<Work> all1 = workService.findAll(pageObj1);
            req.setAttribute("works",all1);
            PageObj<Member> pageObj2 = new PageObj<Member>();
            MemberService memberService=new MemberService();
            PageObj<Member> all2 = memberService.findAll(pageObj2);
            req.setAttribute("members",all2);
            req.getRequestDispatcher("WEB-INF/jsp/index.jsp").forward(req, resp);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
